package hcom.model.etcInfo.action;

import java.util.List;

import hcom.model.etcInfo.bean.EtcInfoBean;
import hcom.model.etcInfo.dao.EtcInfoDao;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.opensymphony.xwork2.Preparable;

public class EtcInfoAction extends ActionSupport implements Preparable, ModelDriven<EtcInfoBean> {
	private EtcInfoBean etcInfoBean;
	private List<EtcInfoBean> list;
	private List<EtcInfoBean> courtlist;
	private List<EtcInfoBean> loglist;
	
	private EtcInfoDao dao = EtcInfoDao.getInstance();
	
	public String getAclList() throws Exception {
		list = dao.getAclList();
		etcInfoBean.setTotalCount(dao.getAclCount());
		
		return SUCCESS;
	}
	
	public String insertAcl() throws Exception {
		dao.insertAcl(etcInfoBean);
		
		return SUCCESS;
	}
	
	public String deleteAcl() throws Exception {
		dao.deleteAcl(etcInfoBean.getIp_seq());
		
		return SUCCESS;
	}
	
	public String getLoginLog() throws Exception {
		
		list = dao.getLoginLog(etcInfoBean);
		System.out.println("year : "+etcInfoBean.getYear());
		return SUCCESS;
	}
	
	public String getCode() throws Exception {
		list = dao.getCode();
		
		return SUCCESS;
	}
	
	public String caseLog() throws Exception {
		list = dao.caseLog();
		
		EtcInfoBean etcBean = new EtcInfoBean();
		
		for(int i = 0; i<list.size(); i++){
			
			list.get(i).setSummary(replaceStr(list.get(i).getSummary()));
			
		}
		return SUCCESS;
	}
	
	
	public String replaceStr(String original) throws Exception{
		String changedStr = "";
		
		changedStr = original.replaceAll("<(/)?([a-zA-Z]*)(\\s[a-zA-Z]*=[^>]*)?(\\s)*(/)?>", "");
		//System.out.println("changedStr : " + changedStr);
		changedStr = changedStr.replace("&nbsp;", "");
		return changedStr;
	}
	
	
	@Override
	public EtcInfoBean getModel() {
		// TODO Auto-generated method stub
		return etcInfoBean;
	}

	@Override
	public void prepare() throws Exception {
		// TODO Auto-generated method stub
		etcInfoBean = new EtcInfoBean();
	}

	public EtcInfoBean getEtcInfoBean() {
		return etcInfoBean;
	}

	public void setEtcInfoBean(EtcInfoBean etcInfoBean) {
		this.etcInfoBean = etcInfoBean;
	}

	public List<EtcInfoBean> getCourtlist() {
		return courtlist;
	}

	public void setCourtlist(List<EtcInfoBean> courtlist) {
		this.courtlist = courtlist;
	}

	public List<EtcInfoBean> getLoglist() {
		return loglist;
	}

	public void setLoglist(List<EtcInfoBean> loglist) {
		this.loglist = loglist;
	}

	public List<EtcInfoBean> getList() {
		return list;
	}

	public void setList(List<EtcInfoBean> list) {
		this.list = list;
	}

}
